<template>
  <div>
    <ul>
      <li
        v-for="m in messagelist"
        :key="m.id"
      >
        <!-- <router-link :to="`/home/message/detail/${m.id}/${m.title}`">  -->

        <router-link
          :to="{
            name: 'xijie',
            // path: '/home/message/detail',
            params: {
              id: m.id,
              title: m.title,
            },
          }"
        >
          <!-- 字符串传递query参数 
         <router-link :to="`/home/message/detail?id=${m.id}&title=${m.title}`"> 
         <router-link
          :to="{
            name: 'xijie',
            // path: '/home/message/detail',
            query: {
              id: m.id,
              title: m.title,
            },
          }"
        >  -->
          {{ m.title }}
        </router-link>
        <button @click="push(m)">push查看</button>
        <button @click="replace(m)">replace查看</button>
        &nbsp;&nbsp;
      </li>
      <router-view></router-view>
    </ul>
  </div>
</template>

<script>
  export default {
    name: "Message",
    data() {
      return {
        messagelist: [
          { id: "002", title: "消息002" },
          { id: "001", title: "消息001" },
          { id: "003", title: "消息003" },
        ],
      }
    },
    methods: {
      push(m) {
        this.$router.push({
          name: "xijie",
          params: {
            id: m.id,
            title: m.title,
          },
        })
      },
      replace(m) {
        this.$router.replace({
          name: "xijie",
          params: {
            id: m.id,
            title: m.title,
          },
        })
      },
    },
  }
</script>
